/*
 *	작성날짜 : 10월 15일
 *	작성자 : 이민선 	
 */
package jangdolbaeng2.customer.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import jangdolbaeng2.db.MybatisConfig;
import jangdolbaeng2.vo.CustomerVO;
import jangdolbaeng2.vo.ZipcodeVO;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

//회원관련 DB 처리
public class CustomerDAO {
	private SqlSessionFactory factory = MybatisConfig.getSqlSessionFactory();
	
	//회원정보 하나 읽기 
	public CustomerVO getCustomer(String customer_id) throws SQLException {
		SqlSession ss = null;
		CustomerVO customer = null;
		
		try {
			ss = factory.openSession();
			customer = ss.selectOne("customer.selectCustomer", customer_id);
			System.out.println("DAO : " + customer_id);
			ss.commit();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			ss.close();
		}
		return customer;
	}
	
	//회원정보 저장
	public void insertCustomer (CustomerVO customer) throws SQLException {
		SqlSession ss = null;
		
		try {
			ss = factory.openSession();
			ss.insert("customer.insertCustomer", customer);
			ss.commit();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			ss.close();
		}
	}
	
	//우편번호 검색
	public List<ZipcodeVO> selectZip(String searchText) throws SQLException{
		SqlSession ss = null;
		List<ZipcodeVO> zipList = new ArrayList<ZipcodeVO>();
		
		try {
			ss = factory.openSession();
			zipList = ss.selectList("customer.selectZip", searchText);
			ss.commit();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			ss.close();
		} 
		return zipList;
	}
}
